<template>
  <view class="personal-center-container">
    <!-- 顶部编辑按钮 -->
    <view class="top" @click="goToEdit">
      编辑
    </view>
    
    <!-- 用户信息头部 -->
    <view class="header">
      <view class="avatar-container">
        <image class="avatar" src="../../static/avatar/ava1.png" mode="aspectFill" ></image>
		
        <view class="nickname">{{nickname}}</view>
		
      </view>
      
      <!-- 数据统计 -->
      <view class="stats-container">
        <view class="stat-item" @click="goToMyCourses">
          <view class="stat-num">{{purchaseCourseNum}}</view>
          <view class="stat-label">我的课程</view>
        </view>
        <view class="stat-item" @click="goToMyLikes">
          <view class="stat-num">{{likeNum}}</view>
          <view class="stat-label">获赞</view>
        </view>
        <view class="stat-item" @click="goToMyCollect">
          <view class="stat-num">{{collectNum}}</view>
          <view class="stat-label">收藏</view>
        </view>
      </view>
    </view>
    
    <!-- 功能列表 -->
    <view class="function-list">
      <view v-for="item in centerList" :key="item.index" class="function-item" @click="navigateTo(item.path)">
        <u-icon :name="item.icon" size="24" color="#333"></u-icon>
        <view class="function-label">{{item.funName}}</view>
        <u-icon name="arrow-right" size="20" color="#999"></u-icon>
      </view>
    </view>
    
    <!-- 底部安全区域 -->
    <view class="safe-area-bottom"></view>
    
    <!-- 悬浮按钮 - AI客服 -->
    <view class="float-button" @click="openAIService">
      <u-icon name="server-man" size="28" color="#FFFFFF"></u-icon>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      nickname: 'AxisKK', // 昵称，可从后端获取
      purchaseCourseNum: '19', // 购买课程数，可从后端获取
      likeNum: '630', // 点赞数，可从后端获取
      collectNum: '0', // 收藏数，可从后端获取
      
      // 功能列表数据
      centerList: [
        { index: 1, funName: "实名认证", icon: "account", path: "/pages/real-name-auth/real-name-auth" },
        { index: 2, funName: "我的评论", icon: "chat", path: "/pages/my-comments/my-comments" },
        { index: 3, funName: "我的收藏", icon: "star", path: "/pages/my-collect/my-collect" },
        { index: 4, funName: "我的订单", icon: "order", path: "/pages/my-orders/my-orders" },
        { index: 5, funName: "激活码兑换", icon: "gift", path: "/pages/code-exchange/code-exchange" },
        { index: 6, funName: "我的钱包", icon: "red-packet", path: "/pages/my-wallet/my-wallet" },
        { index: 7, funName: "我的作业", icon: "list-dot", path: "/pages/my-homework/my-homework" },
        { index: 8, funName: "设置", icon: "setting", path: "/pages/settings/settings" },
        { index: 9, funName: "退出登录", icon: "close-circle", path: "/pages/login/login" }
      ],
	  
    };
  },
  methods: {
    // 导航到指定页面
    navigateTo(path) {
      if (path === "/pages/login/login") {
        // 退出登录逻辑
        uni.showModal({
          title: '确认退出',
          content: '确定要退出当前账号吗？',
          success: (res) => {
            if (res.confirm) {
              // 清除本地存储的用户信息
              uni.removeStorageSync('userInfo');
              uni.navigateTo({ url: path });
            }
          }
        });
      } else {
        uni.navigateTo({ url: path });
      }
    },
    
    // 编辑个人信息
    goToEdit() {
      uni.navigateTo({ url: '/pages/person-info/person-info' });
    },
	
    
    // 我的课程
    goToMyCourses() {
		console.log("跳转我的课程");
    //   uni.navigateTo({ url: '/pages/my-courses/my-courses' });
    },
    
    // 我的喜欢
    goToMyLikes() {
		console.log("跳转我的喜欢");
      // uni.navigateTo({ url: '/pages/my-likes/my-likes' });
    },
    
    // 我的收藏
    goToMyCollect() {
		console.log("跳转我的收藏");
      // uni.navigateTo({ url: '/pages/my-collect/my-collect' });
    },
    
    // 打开AI客服
    openAIService() {
      uni.showToast({
        title: 'AI客服即将上线',
        icon: 'none'
      });
    }
  }
};
</script>

<style lang="scss">
.personal-center-container {
  padding: 40rpx;
  background-color: #f8f8f8;
  min-height: 100vh;
  box-sizing: border-box;
  
  .top {
    text-align: right;
    font-size: 28rpx;
    padding-right: 20rpx;
  }
  
  .header {
    background-color: #FFFFFF;
    border-radius: 16rpx;
    padding: 40rpx 0;
    margin-bottom: 40rpx;
    box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
    
    .avatar-container {
      display: flex;
      flex-direction: column;
      align-items: center;
      
      .avatar {
        width: 160rpx;
        height: 160rpx;
        border-radius: 50%;
        margin-bottom: 20rpx;
        border: 2rpx solid #FFFFFF;
        box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
      }
      
      .nickname {
        font-size: 36rpx;
        font-weight: bold;
        color: #333;
      }
    }
    
    .stats-container {
      display: flex;
      justify-content: space-around;
      margin-top: 40rpx;
      width: 100%;
      
      .stat-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        
        .stat-num {
          font-size: 40rpx;
          font-weight: bold;
          color: #333;
          margin-bottom: 8rpx;
        }
        
        .stat-label {
          font-size: 28rpx;
          color: #666;
        }
      }
    }
  }
  
  .function-list {
    background-color: #FFFFFF;
    border-radius: 16rpx;
    box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
    
    .function-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 30rpx 40rpx;
      border-bottom: 1rpx solid #f5f5f5;
      
      &:last-child {
        border-bottom: none;
      }
      
      .function-label {
        font-size: 32rpx;
        color: #333;
        flex: 1;
        margin-left: 30rpx;
      }
    }
  }
  
  .safe-area-bottom {
    height: 60rpx;
  }
  
  .float-button {
    position: fixed;
    bottom: 60rpx;
    right: 40rpx;
    width: 80rpx;
    height: 80rpx;
    background-color: #007AFF;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4rpx 16rpx rgba(0, 122, 255, 0.3);
    z-index: 999;
    transition: all 0.3s ease;
    
    &:active {
      transform: scale(0.95);
    }
  }
}
</style>